#define _CRT_SECURE_NO_WARNINGS


#include<stdio.h>
#include<stdlib.h>


int* addToArrayForm(int* num, int numSize, int k, int* returnSize)
{
    int countNum = numSize;
    int countK = 0;
    int k1 = k;
    while (k1)
    {
        k1 /= 10;
        countK++;
    }

    int countSum = (countK > countNum ? countK : countNum) + 1;
    int* sum = (int*)malloc(countSum * sizeof(int));

    int numi = countNum - 1;
    int next = 0;
    int numK = 0;
    int numN = 0;
    for (int sumi = countSum - 1; sumi > 0; sumi--)
    {
        if (k > 0 && numi >= 0)
        {
            numK = k % 10;
            numN = num[numi];
            sum[sumi] = (numK + numN + next) % 10;
            next = (numK + numN + next) / 10;
        }
        else if (k > 0)
        {
            numK = k % 10;
            sum[sumi] = (numK + next) % 10;
            next = (numK + next) / 10;
        }
        else if (numi >= 0)
        {
            numN = num[numi];
            sum[sumi] = (numN + next) % 10;
            next = (numN + next) / 10;
        }

        numi--;
        k /= 10;
    }

    if (next == 1)
    {
        sum[0] = 1;
        *returnSize = countSum;
        return sum;
    }

    *returnSize = countSum - 1;

    return sum + 1;
}

int main()
{
    int arr[1] = {0};
    int k = 23;
    int i = 0;
    int* ret = addToArrayForm(arr, sizeof(arr) / sizeof(arr[0]), k, &i);

    for (int j = 0; j < i; j++)
    {
        printf("%d", ret[j]);
    }
    

	return 0;
}